#ifndef INPUTTHREAD_H_
#define INPUTTHREAD_H_

#include <Ogre.h>
#include <OIS.h>

#include "../Core/ThreadManagement/Runnable.h"

#include "../Common/Vec2d.h"

#include "../Core/PlayerArray.h"

namespace Input {

class InputThread :
	public Core::ThreadManagement::Runnable,
	public Ogre::WindowEventListener,
	public OIS::KeyListener,
	public OIS::MouseListener
{

    OIS::InputManager* input_manager_;
    OIS::Mouse* mouse_;
    OIS::Keyboard* keyboard_;

    boost::mutex position_mutex_;

    InputThread();
    ~InputThread();

    Vec2i mouse_position_;

    void setMousePosition( int x, int y );

public:

	static InputThread& getInstance() {
		static InputThread instance;
		return instance;
	};

	OIS::Mouse* getMouse() {
		return mouse_;
	}

	/* Po zmianie wielkosci okna zmienia obszar, w jakim przechwytywana bedzie mysz. */
	void windowResized( Ogre::RenderWindow* rw );

	void run();

	void init( size_t window_handle );

	GameLogic::ObjectId getPlayerId() {
		return Core::PlayerArray::getInstance().getLocalPlayer()->getControlledObjectId();
	}

	/* Zwraca pozycje myszy. */
	const Vec2i getMousePosition();

	/* Callback nacisniecia klawisza: */
    bool keyPressed( const OIS::KeyEvent &arg );

    /* Callback zwolnienia klawisza: */
    bool keyReleased( const OIS::KeyEvent &arg );

    /* Callback dla nacisniecia klawisza myszy. */
    bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

    /* Callback dla puszczenia klawisza myszy. */
    bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

    /* Callback dla zmiany polozenia ursora. */
    bool mouseMoved( const OIS::MouseEvent &arg );

};

} //namespace Input

#endif /* INPUTTHREAD_H_ */
